{extend name="public/base"}

{block name="css"}
<style>
    .layui-upload-img {
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
    }
</style>
{/block}

{block name="main"}
<div class="layui-card">
    <form class="layui-form" action="" lay-filter="component-form-group">

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input"  name="name" value="{$data.name|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">logo</label>
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-xs" id="logo" style="margin-top: 10px;">上传图片</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img logo_img" id="logo_src" src="{$data.logo|default=''}">
                        <p id="id_card_front_text"></p>
                    </div>
                </div>
                <input type="hidden" name="logo" value="{$data.logo|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">首页推荐</label>
            <div class="layui-input-inline">
                <input type="checkbox" lay-skin="switch" lay-text="ON|OFF" lay-filter="recommend" {eq name="data.recommend|default=0" value="1"} checked {/eq}>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">广告语</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input"  name="slogan" value="{$data.slogan|default=''}">
            </div>
        </div>

        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                    <input type="hidden" name="recommend" value="{$data.recommend|default=0}">
                    <input type="hidden" name="id" value="{$data.id|default=0}">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
                </div>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="js"}
<script>
    layui.config({
        base: '/layui_admin/src/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'multiSelect', 'upload', 'layedit'], function () {
        let $ = layui.$
            , form = layui.form, admin = layui.admin, layer = layui.layer, multiSelect = layui.multiSelect, upload = layui.upload, layedit = layui.layedit;

        upload_action($, upload, 'logo'); // 上传品牌logo

        form.on('switch(recommend)', function(data){
            if (data.elem.checked)  {
                $('input[name="recommend"]').val(1);
            } else {
                $('input[name="recommend"]').val(0);
            }
        });

        /* 监听提交 */
        form.on('submit(component-form-demo1)', function (data) {
            layer.load();

            //请求登入接口
            admin.req({
                url: "{:url('save_brand')}" //实际使用请改成服务端真实接口
                ,type : 'post'
                ,data: data.field
                ,done: function(res){
                    //登入成功的提示与跳转
                    layer.msg('保存成功', {
                        offset: '15px'
                        ,icon: 1
                        ,time: 1000
                    }, function(){
                        parent.location.reload(); //刷新页面
                    });
                }
            });
            return false;
        });
    });
</script>
{/block}